<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        #box{
            height:100px;
            width:100px;
            background-color: red;
            position: relative;
            left:0;
            top:0;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <script>
      //固定速度移动盒子  每10ms,移动5px
      var html=document.documentElement||document.body;
      var allWidth=html.clientWidth-box.offsetWidth;//总路程
      var timer=null,step=5,l=0;
      box.onclick=function(){
         timer=setInterval(()=>{
            l+=step;
            if(l>=allWidth){
                box.style.left=allWidth+"px";
                clearInterval(timer);
                timer=null;
                return;
            }
            box.style.left=l+"px";
         },10)
      }
    </script>
</body>
</html>